package com.ruoyi.web.controller.applet;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.applet.domain.test;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.applet.domain.MiniBrandModel;
import com.ruoyi.applet.service.IMiniBrandModelService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 汽车型号Controller
 *
 * @author liucan
 * @date 2024-04-08
 */
@RestController
@RequestMapping("/applet/brandModel")
public class MiniBrandModelController extends BaseController {
    @Resource
    private IMiniBrandModelService miniBrandModelService;

    /**
     * 查询汽车型号列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MiniBrandModel miniBrandModel) {
        startPage();
        List<MiniBrandModel> list = miniBrandModelService.selectMiniBrandModelList(miniBrandModel);
        return getDataTable(list,null);
    }

    /**
     * 导出汽车型号列表
     */
    @Log(title = "汽车型号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MiniBrandModel miniBrandModel) {
        List<MiniBrandModel> list = miniBrandModelService.selectMiniBrandModelList(miniBrandModel);
        ExcelUtil<MiniBrandModel> util = new ExcelUtil<MiniBrandModel>(MiniBrandModel.class);
        util.exportExcel(response, list, "汽车型号数据");
    }

    /**
     * 获取汽车型号详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(miniBrandModelService.selectMiniBrandModelById(id));
    }

    /**
     * 新增汽车型号
     */
    @Log(title = "汽车型号", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MiniBrandModel miniBrandModel) {
        return toAjax(miniBrandModelService.insertMiniBrandModel(miniBrandModel));
    }

    /**
     * 修改汽车型号
     */
    @Log(title = "汽车型号", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MiniBrandModel miniBrandModel) {
        return toAjax(miniBrandModelService.updateMiniBrandModel(miniBrandModel));
    }

    /**
     * 删除汽车型号
     */
    @Log(title = "汽车型号", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(miniBrandModelService.deleteMiniBrandModelByIds(ids));
    }

    /**
     * 测试添加汽车型号
     */
    @PostMapping("/getCard")
    public int addBrandModel(@RequestBody test test) {
        String id = test.getId();//品牌id
        for (String model : test.getList()){//循环获取汽车型号
            MiniBrandModel miniBrandModel = new MiniBrandModel();
            miniBrandModel.setBrId(id);//id
            miniBrandModel.setBrModel(model);//型号
            miniBrandModelService.insertMiniBrandModel(miniBrandModel);
        }
        return 1;
    }
}
